﻿using System;
using System.Runtime.InteropServices;

namespace SkinableFormsLib
{
	public class Win32
	{


		[StructLayout(LayoutKind.Sequential)]
		public struct SCROLLINFO
		{
			public int cbSize;
			public uint fMask;
			public int nMin;
			public int nMax;
			public uint nPage;
			public int nPos;
			public int nTrackPos;
		}

		public enum ScrollBarDirection
		{
			SB_HORZ = 0,
			SB_VERT = 1,
			SB_CTL = 2,
			SB_BOTH = 3
		}

		public enum ScrollInfoMask
		{
			SIF_RANGE = 0x1,
			SIF_PAGE = 0x2,
			SIF_POS = 0x4,
			SIF_DISABLENOSCROLL = 0x8,
			SIF_TRACKPOS = 0x10,
			SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
		}

		[DllImport("user32.dll")]
		[return: MarshalAs(UnmanagedType.Bool)]
		private static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);

		public static int GetScrollInfo(IntPtr handle)
		{
			SCROLLINFO si = new SCROLLINFO();
			si.cbSize = Marshal.SizeOf(si);
			si.fMask = (int)ScrollInfoMask.SIF_POS;
			GetScrollInfo(handle, (int)(ScrollBarDirection.SB_VERT), ref si);
			int vp=si.nPos;
			GetScrollInfo(handle, (int)(ScrollBarDirection.SB_HORZ), ref si);
			int hp=si.nPos;

			
			return Utils.MAKELONG(hp, vp);
		}


		public static SCROLLINFO GetScrollInfoEx(IntPtr handle, ScrollBarDirection typeBar)
		{
			SCROLLINFO si = new SCROLLINFO();
			si.cbSize = Marshal.SizeOf(si);
			si.fMask = (int)ScrollInfoMask.SIF_ALL;
			GetScrollInfo(handle, (int)typeBar, ref si);
			return si;
		}



		#region Constants for Listview-Messages
		public const int LVM_FIRST = 4096;
		public const int LVM_SETGROUPMETRICS = (LVM_FIRST + 155);
		#endregion

		#region Constants for LVGROUPMETRICS.mask
		public const int LVGMF_NONE = 0;
		public const int LVGMF_BORDERSIZE = 1;
		public const int LVGMF_BORDERCOLOR = 2;
		public const int LVGMF_TEXTCOLOR = 4;
		
		#endregion

		[StructLayout(LayoutKind.Sequential)]
		public struct LVGROUPMETRICS
		{
			public int cbSize;
			public int mask;
			public int Left;
			public int Top;
			public int Right;
			public int Bottom;
			public int crLeft;
			public int crTop;
			public int crRight;
			public int crBottom;
			public int crHeader;
			public int crFooter;
		}

		[DllImport("User32.dll")]
		public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int
		wParam, ref LVGROUPMETRICS lParam);

		public static void SetGroupHeaderColor(IntPtr handle, int color)
		{
			LVGROUPMETRICS groupMetrics;
			groupMetrics = new LVGROUPMETRICS();
			groupMetrics.cbSize =
			Marshal.SizeOf(typeof(LVGROUPMETRICS));


			groupMetrics.mask = LVGMF_TEXTCOLOR;
			groupMetrics.crHeader = color;
			int ptrRetVal = (int)SendMessage(handle, LVM_SETGROUPMETRICS, 0, ref groupMetrics);
		}

		[DllImport("user32.dll")]
		public static extern bool ReleaseCapture();
		public enum HitTestValues : int
		{
			HTERROR = -2,
			HTTRANSPARENT = -1,
			HTNOWHERE = 0,
			HTCLIENT = 1,
			HTCAPTION = 2,
			HTSYSMENU = 3,
			HTGROWBOX = 4,
			HTMENU = 5,
			HTHSCROLL = 6,
			HTVSCROLL = 7,
			HTMINBUTTON = 8,
			HTMAXBUTTON = 9,
			HTLEFT = 10,
			HTRIGHT = 11,
			HTTOP = 12,
			HTTOPLEFT = 13,
			HTTOPRIGHT = 14,
			HTBOTTOM = 15,
			HTBOTTOMLEFT = 16,
			HTBOTTOMRIGHT = 17,
			HTBORDER = 18,
			HTOBJECT = 19,
			HTCLOSE = 20,
			HTHELP = 21
		}
		public enum SysCommands : int
		{
			SC_SIZE = 0xF000,
			SC_MOVE = 0xF010,
			SC_MINIMIZE = 0xF020,
			SC_MAXIMIZE = 0xF030,
			SC_NEXTWINDOW = 0xF040,
			SC_PREVWINDOW = 0xF050,
			SC_CLOSE = 0xF060,
			SC_VSCROLL = 0xF070,
			SC_HSCROLL = 0xF080,
			SC_MOUSEMENU = 0xF090,
			SC_KEYMENU = 0xF100,
			SC_ARRANGE = 0xF110,
			SC_RESTORE = 0xF120,
			SC_TASKLIST = 0xF130,
			SC_SCREENSAVE = 0xF140,
			SC_HOTKEY = 0xF150,
			//#if(WINVER >= 0x0400) //Win95
			SC_DEFAULT = 0xF160,
			SC_MONITORPOWER = 0xF170,
			SC_CONTEXTHELP = 0xF180,
			SC_SEPARATOR = 0xF00F,
			//#endif /* WINVER >= 0x0400 */

			//#if(WINVER >= 0x0600) //Vista
			SCF_ISSECURE = 0x00000001,
			//#endif /* WINVER >= 0x0600 */

			/*
			  * Obsolete names
			  */
			SC_ICON = SC_MINIMIZE,
			SC_ZOOM = SC_MAXIMIZE,
		}


		public enum MKS : int
		{
			MK_LBUTTON = 0x0001,
			MK_RBUTTON = 0x0002,
			MK_SHIFT = 0x0004,
			MK_CONTROL = 0x0008,
			MK_MBUTTON = 0x0010,
			MK_ALT = 0x1000
		}

		[return: MarshalAs(UnmanagedType.Bool)]
		[DllImport("user32.dll", SetLastError = true)]
		public static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
		public static bool PostMessageSafe(HandleRef hWnd, uint msg, IntPtr wParam, IntPtr lParam)
		{
			bool returnValue = PostMessage(hWnd, msg, wParam, lParam);

			if (returnValue == false)
			{
				// An error occured
				throw new Exception(Marshal.GetLastWin32Error().ToString());
			}

			return returnValue;
		}





		public static bool HasHScroll(IntPtr handle)
		{
			int style = Win32.GetWindowLong(handle, Win32.GWL_STYLE);
			return ((style & Win32.WS_HSCROLL) != 0);
		}
		public static bool HasVScroll(IntPtr handle)
		{
			int style = Win32.GetWindowLong(handle, Win32.GWL_STYLE);
			return ((style & Win32.WS_VSCROLL) != 0);
		}


		/*internal void GetScrollbarsPosition()
		{
			int style = Win32.GetWindowLong(Handle, Win32.GWL_STYLE);
			bool hasHScroll = ((style & Win32.WS_HSCROLL) != 0);
			bool hasVScroll = ((style & Win32.WS_VSCROLL) != 0);
			Console.WriteLine("{0} {1}", hasHScroll, hasVScroll);
		}	*/


		[DllImport("user32.dll", SetLastError = true)]
		public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);


		// ALTERNATIVE K.I.S.S. VERSION

		public const uint SPI_GETBEEP = 0x0001;
		public const uint SPI_SETBEEP = 0x0002;
		public const uint SPI_GETMOUSE = 0x0003;
		public const uint SPI_SETMOUSE = 0x0004;
		public const uint SPI_GETBORDER = 0x0005;
		public const uint SPI_SETBORDER = 0x0006;
		public const uint SPI_GETKEYBOARDSPEED = 0x000A;
		public const uint SPI_SETKEYBOARDSPEED = 0x000B;
		public const uint SPI_LANGDRIVER = 0x000C;
		public const uint SPI_ICONHORIZONTALSPACING = 0x000D;
		public const uint SPI_GETSCREENSAVETIMEOUT = 0x000E;
		public const uint SPI_SETSCREENSAVETIMEOUT = 0x000F;
		public const uint SPI_GETSCREENSAVEACTIVE = 0x0010;
		public const uint SPI_SETSCREENSAVEACTIVE = 0x0011;
		public const uint SPI_GETGRIDGRANULARITY = 0x0012;
		public const uint SPI_SETGRIDGRANULARITY = 0x0013;
		public const uint SPI_SETDESKWALLPAPER = 0x0014;
		public const uint SPI_SETDESKPATTERN = 0x0015;
		public const uint SPI_GETKEYBOARDDELAY = 0x0016;
		public const uint SPI_SETKEYBOARDDELAY = 0x0017;
		public const uint SPI_ICONVERTICALSPACING = 0x0018;
		public const uint SPI_GETICONTITLEWRAP = 0x0019;
		public const uint SPI_SETICONTITLEWRAP = 0x001A;
		public const uint SPI_GETMENUDROPALIGNMENT = 0x001B;
		public const uint SPI_SETMENUDROPALIGNMENT = 0x001C;
		public const uint SPI_SETDOUBLECLKWIDTH = 0x001D;
		public const uint SPI_SETDOUBLECLKHEIGHT = 0x001E;
		public const uint SPI_GETICONTITLELOGFONT = 0x001F;
		public const uint SPI_SETDOUBLECLICKTIME = 0x0020;
		public const uint SPI_SETMOUSEBUTTONSWAP = 0x0021;
		public const uint SPI_SETICONTITLELOGFONT = 0x0022;
		public const uint SPI_GETFASTTASKSWITCH = 0x0023;
		public const uint SPI_SETFASTTASKSWITCH = 0x0024;
		public const uint SPI_SETDRAGFULLWINDOWS = 0x0025;
		public const uint SPI_GETDRAGFULLWINDOWS = 0x0026;
		public const uint SPI_GETNONCLIENTMETRICS = 0x0029;
		public const uint SPI_SETNONCLIENTMETRICS = 0x002A;
		public const uint SPI_GETMINIMIZEDMETRICS = 0x002B;
		public const uint SPI_SETMINIMIZEDMETRICS = 0x002C;
		public const uint SPI_GETICONMETRICS = 0x002D;
		public const uint SPI_SETICONMETRICS = 0x002E;
		public const uint SPI_SETWORKAREA = 0x002F;
		public const uint SPI_GETWORKAREA = 0x0030;
		public const uint SPI_SETPENWINDOWS = 0x0031;
		public const uint SPI_GETHIGHCONTRAST = 0x0042;
		public const uint SPI_SETHIGHCONTRAST = 0x0043;
		public const uint SPI_GETKEYBOARDPREF = 0x0044;
		public const uint SPI_SETKEYBOARDPREF = 0x0045;
		public const uint SPI_GETSCREENREADER = 0x0046;
		public const uint SPI_SETSCREENREADER = 0x0047;
		public const uint SPI_GETANIMATION = 0x0048;
		public const uint SPI_SETANIMATION = 0x0049;
		public const uint SPI_GETFONTSMOOTHING = 0x004A;
		public const uint SPI_SETFONTSMOOTHING = 0x004B;
		public const uint SPI_SETDRAGWIDTH = 0x004C;
		public const uint SPI_SETDRAGHEIGHT = 0x004D;
		public const uint SPI_SETHANDHELD = 0x004E;
		public const uint SPI_GETLOWPOWERTIMEOUT = 0x004F;
		public const uint SPI_GETPOWEROFFTIMEOUT = 0x0050;
		public const uint SPI_SETLOWPOWERTIMEOUT = 0x0051;
		public const uint SPI_SETPOWEROFFTIMEOUT = 0x0052;
		public const uint SPI_GETLOWPOWERACTIVE = 0x0053;
		public const uint SPI_GETPOWEROFFACTIVE = 0x0054;
		public const uint SPI_SETLOWPOWERACTIVE = 0x0055;
		public const uint SPI_SETPOWEROFFACTIVE = 0x0056;
		public const uint SPI_SETICONS = 0x0058;
		public const uint SPI_GETDEFAULTINPUTLANG = 0x0059;
		public const uint SPI_SETDEFAULTINPUTLANG = 0x005A;
		public const uint SPI_SETLANGTOGGLE = 0x005B;
		public const uint SPI_GETWINDOWSEXTENSION = 0x005C;
		public const uint SPI_SETMOUSETRAILS = 0x005D;
		public const uint SPI_GETMOUSETRAILS = 0x005E;
		public const uint SPI_SCREENSAVERRUNNING = 0x0061;
		public const uint SPI_GETFILTERKEYS = 0x0032;
		public const uint SPI_SETFILTERKEYS = 0x0033;
		public const uint SPI_GETTOGGLEKEYS = 0x0034;
		public const uint SPI_SETTOGGLEKEYS = 0x0035;
		public const uint SPI_GETMOUSEKEYS = 0x0036;
		public const uint SPI_SETMOUSEKEYS = 0x0037;
		public const uint SPI_GETSHOWSOUNDS = 0x0038;
		public const uint SPI_SETSHOWSOUNDS = 0x0039;
		public const uint SPI_GETSTICKYKEYS = 0x003A;
		public const uint SPI_SETSTICKYKEYS = 0x003B;
		public const uint SPI_GETACCESSTIMEOUT = 0x003C;
		public const uint SPI_SETACCESSTIMEOUT = 0x003D;
		public const uint SPI_GETSERIALKEYS = 0x003E;
		public const uint SPI_SETSERIALKEYS = 0x003F;
		public const uint SPI_GETSOUNDSENTRY = 0x0040;
		public const uint SPI_SETSOUNDSENTRY = 0x0041;
		public const uint SPI_GETSNAPTODEFBUTTON = 0x005F;
		public const uint SPI_SETSNAPTODEFBUTTON = 0x0060;
		public const uint SPI_GETMOUSEHOVERWIDTH = 0x0062;
		public const uint SPI_SETMOUSEHOVERWIDTH = 0x0063;
		public const uint SPI_GETMOUSEHOVERHEIGHT = 0x0064;
		public const uint SPI_SETMOUSEHOVERHEIGHT = 0x0065;
		public const uint SPI_GETMOUSEHOVERTIME = 0x0066;
		public const uint SPI_SETMOUSEHOVERTIME = 0x0067;
		public const uint SPI_GETWHEELSCROLLLINES = 0x0068;
		public const uint SPI_SETWHEELSCROLLLINES = 0x0069;
		public const uint SPI_GETMENUSHOWDELAY = 0x006A;
		public const uint SPI_SETMENUSHOWDELAY = 0x006B;
		public const uint SPI_GETSHOWIMEUI = 0x006E;
		public const uint SPI_SETSHOWIMEUI = 0x006F;
		public const uint SPI_GETMOUSESPEED = 0x0070;
		public const uint SPI_SETMOUSESPEED = 0x0071;
		public const uint SPI_GETSCREENSAVERRUNNING = 0x0072;
		public const uint SPI_GETDESKWALLPAPER = 0x0073;
		public const uint SPI_GETACTIVEWINDOWTRACKING = 0x1000;
		public const uint SPI_SETACTIVEWINDOWTRACKING = 0x1001;
		public const uint SPI_GETMENUANIMATION = 0x1002;
		public const uint SPI_SETMENUANIMATION = 0x1003;
		public const uint SPI_GETCOMBOBOXANIMATION = 0x1004;
		public const uint SPI_SETCOMBOBOXANIMATION = 0x1005;
		public const uint SPI_GETLISTBOXSMOOTHSCROLLING = 0x1006;
		public const uint SPI_SETLISTBOXSMOOTHSCROLLING = 0x1007;
		public const uint SPI_GETGRADIENTCAPTIONS = 0x1008;
		public const uint SPI_SETGRADIENTCAPTIONS = 0x1009;
		public const uint SPI_GETKEYBOARDCUES = 0x100A;
		public const uint SPI_SETKEYBOARDCUES = 0x100B;
		public const uint SPI_GETMENUUNDERLINES = SPI_GETKEYBOARDCUES;
		public const uint SPI_SETMENUUNDERLINES = SPI_SETKEYBOARDCUES;
		public const uint SPI_GETACTIVEWNDTRKZORDER = 0x100C;
		public const uint SPI_SETACTIVEWNDTRKZORDER = 0x100D;
		public const uint SPI_GETHOTTRACKING = 0x100E;
		public const uint SPI_SETHOTTRACKING = 0x100F;
		public const uint SPI_GETMENUFADE = 0x1012;
		public const uint SPI_SETMENUFADE = 0x1013;
		public const uint SPI_GETSELECTIONFADE = 0x1014;
		public const uint SPI_SETSELECTIONFADE = 0x1015;
		public const uint SPI_GETTOOLTIPANIMATION = 0x1016;
		public const uint SPI_SETTOOLTIPANIMATION = 0x1017;
		public const uint SPI_GETTOOLTIPFADE = 0x1018;
		public const uint SPI_SETTOOLTIPFADE = 0x1019;
		public const uint SPI_GETCURSORSHADOW = 0x101A;
		public const uint SPI_SETCURSORSHADOW = 0x101B;
		public const uint SPI_GETMOUSESONAR = 0x101C;
		public const uint SPI_SETMOUSESONAR = 0x101D;
		public const uint SPI_GETMOUSECLICKLOCK = 0x101E;
		public const uint SPI_SETMOUSECLICKLOCK = 0x101F;
		public const uint SPI_GETMOUSEVANISH = 0x1020;
		public const uint SPI_SETMOUSEVANISH = 0x1021;
		public const uint SPI_GETFLATMENU = 0x1022;
		public const uint SPI_SETFLATMENU = 0x1023;
		public const uint SPI_GETDROPSHADOW = 0x1024;
		public const uint SPI_SETDROPSHADOW = 0x1025;
		public const uint SPI_GETBLOCKSENDINPUTRESETS = 0x1026;
		public const uint SPI_SETBLOCKSENDINPUTRESETS = 0x1027;
		public const uint SPI_GETUIEFFECTS = 0x103E;
		public const uint SPI_SETUIEFFECTS = 0x103F;
		public const uint SPI_GETFOREGROUNDLOCKTIMEOUT = 0x2000;
		public const uint SPI_SETFOREGROUNDLOCKTIMEOUT = 0x2001;
		public const uint SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002;
		public const uint SPI_SETACTIVEWNDTRKTIMEOUT = 0x2003;
		public const uint SPI_GETFOREGROUNDFLASHCOUNT = 0x2004;
		public const uint SPI_SETFOREGROUNDFLASHCOUNT = 0x2005;
		public const uint SPI_GETCARETWIDTH = 0x2006;
		public const uint SPI_SETCARETWIDTH = 0x2007;
		public const uint SPI_GETMOUSECLICKLOCKTIME = 0x2008;
		public const uint SPI_SETMOUSECLICKLOCKTIME = 0x2009;
		public const uint SPI_GETFONTSMOOTHINGTYPE = 0x200A;
		public const uint SPI_SETFONTSMOOTHINGTYPE = 0x200B;
		public const uint SPI_GETFONTSMOOTHINGCONTRAST = 0x200C;
		public const uint SPI_SETFONTSMOOTHINGCONTRAST = 0x200D;
		public const uint SPI_GETFOCUSBORDERWIDTH = 0x200E;
		public const uint SPI_SETFOCUSBORDERWIDTH = 0x200F;
		public const uint SPI_GETFOCUSBORDERHEIGHT = 0x2010;
		public const uint SPI_SETFOCUSBORDERHEIGHT = 0x2011;
		public const uint SPI_GETFONTSMOOTHINGORIENTATION = 0x2012;
		public const uint SPI_SETFONTSMOOTHINGORIENTATION = 0x2013;

		public const int SPIF_UPDATEINIFILE = 0x1;
		public const int SPIF_SENDCHANGE = 0x1;
		public const int FE_FONTSMOOTHINGSTANDARD = 0x1;
		public const int FE_FONTSMOOTHINGCLEARTYPE = 0x2;


		public static bool SmoothingModeIsClearType()
		{
			return (System.Windows.Forms.SystemInformation.FontSmoothingType == Win32.FE_FONTSMOOTHINGCLEARTYPE);
		}





		//SPI_GETCLEARTYPE //Vista
		//SPI_SETCLEARTYPE //Vista
		//SPI_GETFONTSMOOTHINGTYPE //XP
		//SPI_SETFONTSMOOTHINGTYPE //XP
		//FE_FONTSMOOTHINGSTANDARD //XP
		//FE_FONTSMOOTHINGCLEARTYPE //XP

		/*
  public static bool IsClearTypeOn()
  {
	  int pv = 0;
	  SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, ref pv, 0);
	  //SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, ref pv, 0);
	  if (pv == FE_FONTSMOOTHINGCLEARTYPE)
	  {
		  return true;

	  }
	  return false;

  }


  public static void SetFontSmoothingType(int fst)
  {
	  if (!IsFontSmoothingOn())
		  return;
	  EnableFontSmoothing();
	  int pv = 1;
	  SystemParametersInfo(SPI_SETFONTSMOOTHINGTYPE, 0,ref pv, 1|2);
	  Console.WriteLine("set smootg ");

			
  }

  public static bool IsFontSmoothingOn()
  {
	  int pv = 0;
	  SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, ref pv, 0);
	  if (pv >0)
	  {
		  return true;

	  }
	  return false;
  }

  public static void DisableFontSmoothing()
  {
	  int pv = 0;
	  SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, ref pv, SPIF_UPDATEINIFILE);
  }

  public static void EnableFontSmoothing()
  {
	  int pv = 0;
	  SystemParametersInfo(SPI_SETFONTSMOOTHING, 1, ref pv, SPIF_UPDATEINIFILE);
  }
*/










		public const int GWL_STYLE = -16;
		public const int WS_VSCROLL = 0x00200000;
		public const int WS_HSCROLL = 0x00100000;

		[DllImport("user32.dll", ExactSpelling = false, CharSet = CharSet.Auto)]
		public static extern int GetWindowLong(IntPtr hWnd, int nIndex);



		public enum TernaryRasterOperations : uint
		{
			/// <summary>dest = source</summary>
			SRCCOPY = 0x00CC0020,
			/// <summary>dest = source OR dest</summary>
			SRCPAINT = 0x00EE0086,
			/// <summary>dest = source AND dest</summary>
			SRCAND = 0x008800C6,
			/// <summary>dest = source XOR dest</summary>
			SRCINVERT = 0x00660046,
			/// <summary>dest = source AND (NOT dest)</summary>
			SRCERASE = 0x00440328,
			/// <summary>dest = (NOT source)</summary>
			NOTSRCCOPY = 0x00330008,
			/// <summary>dest = (NOT src) AND (NOT dest)</summary>
			NOTSRCERASE = 0x001100A6,
			/// <summary>dest = (source AND pattern)</summary>
			MERGECOPY = 0x00C000CA,
			/// <summary>dest = (NOT source) OR dest</summary>
			MERGEPAINT = 0x00BB0226,
			/// <summary>dest = pattern</summary>
			PATCOPY = 0x00F00021,
			/// <summary>dest = DPSnoo</summary>
			PATPAINT = 0x00FB0A09,
			/// <summary>dest = pattern XOR dest</summary>
			PATINVERT = 0x005A0049,
			/// <summary>dest = (NOT dest)</summary>
			DSTINVERT = 0x00550009,
			/// <summary>dest = BLACK</summary>
			BLACKNESS = 0x00000042,
			/// <summary>dest = WHITE</summary>
			WHITENESS = 0x00FF0062
		}
		[DllImport("gdi32.dll")]
		public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth,
		   int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);





		public const int RDW_INVALIDATE = 0x0001;
		public const int RDW_INTERNALPAINT = 0x0002;
		public const int RDW_ERASE = 0x0004;

		public const int RDW_VALIDATE = 0x0008;
		public const int RDW_NOINTERNALPAINT = 0x0010;
		public const int RDW_NOERASE = 0x0020;

		public const int RDW_NOCHILDREN = 0x0040;
		public const int RDW_ALLCHILDREN = 0x0080;

		public const int RDW_UPDATENOW = 0x0100;
		public const int RDW_ERASENOW = 0x0200;

		public const int RDW_FRAME = 0x0400;
		public const int RDW_NOFRAME = 0x0800;

		[StructLayout(LayoutKind.Sequential)]
		public struct RECT
		{
			public int Left;
			public int Top;
			public int Right;
			public int Bottom;
		}

		[DllImport("user32.dll")]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool RedrawWindow(IntPtr hWnd, [In] ref RECT lprcUpdate, IntPtr hrgnUpdate, uint flags);
		[DllImport("user32.dll")]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, uint flags);

		public enum Bool
		{
			False = 0,
			True
		};


		[StructLayout(LayoutKind.Sequential)]
		public struct Point
		{
			public Int32 x;
			public Int32 y;

			public Point(Int32 x, Int32 y) { this.x = x; this.y = y; }
		}


		[StructLayout(LayoutKind.Sequential)]
		public struct Size
		{
			public Int32 cx;
			public Int32 cy;

			public Size(Int32 cx, Int32 cy) { this.cx = cx; this.cy = cy; }
		}


		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		struct ARGB
		{
			public byte Blue;
			public byte Green;
			public byte Red;
			public byte Alpha;
		}


		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct BLENDFUNCTION
		{
			public byte BlendOp;
			public byte BlendFlags;
			public byte SourceConstantAlpha;
			public byte AlphaFormat;
		}


		public const Int32 ULW_COLORKEY = 0x00000001;
		public const Int32 ULW_ALPHA = 0x00000002;
		public const Int32 ULW_OPAQUE = 0x00000004;

		public const byte AC_SRC_OVER = 0x00;
		public const byte AC_SRC_ALPHA = 0x01;


		public const Int32 WM_ACTIVATE = 0x0006;
		public const Int32 WM_ACTIVATEAPP = 0x001C;
		public const Int32 WM_AFXFIRST = 0x0360;
		public const Int32 WM_AFXLAST = 0x037F;
		public const Int32 WM_APP = 0x8000;
		public const Int32 WM_ASKCBFORMATNAME = 0x030C;
		public const Int32 WM_CANCELJOURNAL = 0x004B;
		public const Int32 WM_CANCELMODE = 0x001F;
		public const Int32 WM_CAPTURECHANGED = 0x0215;
		public const Int32 WM_CHANGECBCHAIN = 0x030D;
		public const Int32 WM_CHANGEUISTATE = 0x0127;
		public const Int32 WM_CHAR = 0x0102;
		public const Int32 WM_CHARTOITEM = 0x002F;
		public const Int32 WM_CHILDACTIVATE = 0x0022;
		public const Int32 WM_CLEAR = 0x0303;
		public const Int32 WM_CLOSE = 0x0010;
		public const Int32 WM_COMMAND = 0x0111;
		public const Int32 WM_COMPACTING = 0x0041;
		public const Int32 WM_COMPAREITEM = 0x0039;
		public const Int32 WM_CONTEXTMENU = 0x007B;
		public const Int32 WM_COPY = 0x0301;
		public const Int32 WM_COPYDATA = 0x004A;
		public const Int32 WM_CREATE = 0x0001;
		public const Int32 WM_CTLCOLORBTN = 0x0135;
		public const Int32 WM_CTLCOLORDLG = 0x0136;
		public const Int32 WM_CTLCOLOREDIT = 0x0133;
		public const Int32 WM_CTLCOLORLISTBOX = 0x0134;
		public const Int32 WM_CTLCOLORMSGBOX = 0x0132;
		public const Int32 WM_CTLCOLORSCROLLBAR = 0x0137;
		public const Int32 WM_CTLCOLORSTATIC = 0x0138;
		public const Int32 WM_CUT = 0x0300;
		public const Int32 WM_DEADCHAR = 0x0103;
		public const Int32 WM_DELETEITEM = 0x002D;
		public const Int32 WM_DESTROY = 0x0002;
		public const Int32 WM_DESTROYCLIPBOARD = 0x0307;
		public const Int32 WM_DEVICECHANGE = 0x0219;
		public const Int32 WM_DEVMODECHANGE = 0x001B;
		public const Int32 WM_DISPLAYCHANGE = 0x007E;
		public const Int32 WM_DRAWCLIPBOARD = 0x0308;
		public const Int32 WM_DRAWITEM = 0x002B;
		public const Int32 WM_DROPFILES = 0x0233;
		public const Int32 WM_ENABLE = 0x000A;
		public const Int32 WM_ENDSESSION = 0x0016;
		public const Int32 WM_ENTERIDLE = 0x0121;
		public const Int32 WM_ENTERMENULOOP = 0x0211;
		public const Int32 WM_ENTERSIZEMOVE = 0x0231;
		public const Int32 WM_ERASEBKGND = 0x0014;
		public const Int32 WM_EXITMENULOOP = 0x0212;
		public const Int32 WM_EXITSIZEMOVE = 0x0232;
		public const Int32 WM_FONTCHANGE = 0x001D;
		public const Int32 WM_GETDLGCODE = 0x0087;
		public const Int32 WM_GETFONT = 0x0031;
		public const Int32 WM_GETHOTKEY = 0x0033;
		public const Int32 WM_GETICON = 0x007F;
		public const Int32 WM_GETMINMAXINFO = 0x0024;
		public const Int32 WM_GETOBJECT = 0x003D;
		public const Int32 WM_GETTEXT = 0x000D;
		public const Int32 WM_GETTEXTLENGTH = 0x000E;
		public const Int32 WM_HANDHELDFIRST = 0x0358;
		public const Int32 WM_HANDHELDLAST = 0x035F;
		public const Int32 WM_HELP = 0x0053;
		public const Int32 WM_HOTKEY = 0x0312;
		public const Int32 WM_HSCROLL = 0x0114;
		public const Int32 WM_HSCROLLCLIPBOARD = 0x030E;
		public const Int32 WM_ICONERASEBKGND = 0x0027;
		public const Int32 WM_IME_CHAR = 0x0286;
		public const Int32 WM_IME_COMPOSITION = 0x010F;
		public const Int32 WM_IME_COMPOSITIONFULL = 0x0284;
		public const Int32 WM_IME_CONTROL = 0x0283;
		public const Int32 WM_IME_ENDCOMPOSITION = 0x010E;
		public const Int32 WM_IME_KEYDOWN = 0x0290;
		public const Int32 WM_IME_KEYLAST = 0x010F;
		public const Int32 WM_IME_KEYUP = 0x0291;
		public const Int32 WM_IME_NOTIFY = 0x0282;
		public const Int32 WM_IME_REQUEST = 0x0288;
		public const Int32 WM_IME_SELECT = 0x0285;
		public const Int32 WM_IME_SETCONTEXT = 0x0281;
		public const Int32 WM_IME_STARTCOMPOSITION = 0x010D;
		public const Int32 WM_INITDIALOG = 0x0110;
		public const Int32 WM_INITMENU = 0x0116;
		public const Int32 WM_INITMENUPOPUP = 0x0117;
		public const Int32 WM_INPUTLANGCHANGE = 0x0051;
		public const Int32 WM_INPUTLANGCHANGEREQUEST = 0x0050;
		public const Int32 WM_KEYDOWN = 0x0100;
		public const Int32 WM_KEYFIRST = 0x0100;
		public const Int32 WM_KEYLAST = 0x0108;
		public const Int32 WM_KEYUP = 0x0101;
		public const Int32 WM_KILLFOCUS = 0x0008;
		public const Int32 WM_LBUTTONDBLCLK = 0x0203;
		public const Int32 WM_LBUTTONDOWN = 0x0201;
		public const Int32 WM_LBUTTONUP = 0x0202;
		public const Int32 WM_MBUTTONDBLCLK = 0x0209;
		public const Int32 WM_MBUTTONDOWN = 0x0207;
		public const Int32 WM_MBUTTONUP = 0x0208;
		public const Int32 WM_MDIACTIVATE = 0x0222;
		public const Int32 WM_MDICASCADE = 0x0227;
		public const Int32 WM_MDICREATE = 0x0220;
		public const Int32 WM_MDIDESTROY = 0x0221;
		public const Int32 WM_MDIGETACTIVE = 0x0229;
		public const Int32 WM_MDIICONARRANGE = 0x0228;
		public const Int32 WM_MDIMAXIMIZE = 0x0225;
		public const Int32 WM_MDINEXT = 0x0224;
		public const Int32 WM_MDIREFRESHMENU = 0x0234;
		public const Int32 WM_MDIRESTORE = 0x0223;
		public const Int32 WM_MDISETMENU = 0x0230;
		public const Int32 WM_MDITILE = 0x0226;
		public const Int32 WM_MEASUREITEM = 0x002C;
		public const Int32 WM_MENUCHAR = 0x0120;
		public const Int32 WM_MENUCOMMAND = 0x0126;
		public const Int32 WM_MENUDRAG = 0x0123;
		public const Int32 WM_MENUGETOBJECT = 0x0124;
		public const Int32 WM_MENURBUTTONUP = 0x0122;
		public const Int32 WM_MENUSELECT = 0x011F;
		public const Int32 WM_MOUSEACTIVATE = 0x0021;
		public const Int32 WM_MOUSEFIRST = 0x0200;
		public const Int32 WM_MOUSEHOVER = 0x02A1;
		public const Int32 WM_MOUSELAST = 0x020D;
		public const Int32 WM_MOUSELEAVE = 0x02A3;
		public const Int32 WM_MOUSEMOVE = 0x0200;
		public const Int32 WM_MOUSEWHEEL = 0x020A;
		public const Int32 WM_MOUSEHWHEEL = 0x020E;
		public const Int32 WM_MOVE = 0x0003;
		public const Int32 WM_MOVING = 0x0216;
		public const Int32 WM_NCACTIVATE = 0x0086;
		public const Int32 WM_NCCALCSIZE = 0x0083;
		public const Int32 WM_NCCREATE = 0x0081;
		public const Int32 WM_NCDESTROY = 0x0082;
		public const Int32 WM_NCHITTEST = 0x0084;
		public const Int32 WM_NCLBUTTONDBLCLK = 0x00A3;
		public const Int32 WM_NCLBUTTONDOWN = 0x00A1;
		public const Int32 WM_NCLBUTTONUP = 0x00A2;
		public const Int32 WM_NCMBUTTONDBLCLK = 0x00A9;
		public const Int32 WM_NCMBUTTONDOWN = 0x00A7;
		public const Int32 WM_NCMBUTTONUP = 0x00A8;
		public const Int32 WM_NCMOUSEMOVE = 0x00A0;
		public const Int32 WM_NCPAINT = 0x0085;
		public const Int32 WM_NCRBUTTONDBLCLK = 0x00A6;
		public const Int32 WM_NCRBUTTONDOWN = 0x00A4;
		public const Int32 WM_NCRBUTTONUP = 0x00A5;
		public const Int32 WM_NEXTDLGCTL = 0x0028;
		public const Int32 WM_NEXTMENU = 0x0213;
		public const Int32 WM_NOTIFY = 0x004E;
		public const Int32 WM_NOTIFYFORMAT = 0x0055;
		public const Int32 WM_NULL = 0x0000;
		public const Int32 WM_PAINT = 0x000F;
		public const Int32 WM_PAINTCLIPBOARD = 0x0309;
		public const Int32 WM_PAINTICON = 0x0026;
		public const Int32 WM_PALETTECHANGED = 0x0311;
		public const Int32 WM_PALETTEISCHANGING = 0x0310;
		public const Int32 WM_PARENTNOTIFY = 0x0210;
		public const Int32 WM_PASTE = 0x0302;
		public const Int32 WM_PENWINFIRST = 0x0380;
		public const Int32 WM_PENWINLAST = 0x038F;
		public const Int32 WM_POWER = 0x0048;
		public const Int32 WM_POWERBROADCAST = 0x0218;
		public const Int32 WM_PRINT = 0x0317;
		public const Int32 WM_PRINTCLIENT = 0x0318;
		public const Int32 WM_QUERYDRAGICON = 0x0037;
		public const Int32 WM_QUERYENDSESSION = 0x0011;
		public const Int32 WM_QUERYNEWPALETTE = 0x030F;
		public const Int32 WM_QUERYOPEN = 0x0013;
		public const Int32 WM_QUEUESYNC = 0x0023;
		public const Int32 WM_QUIT = 0x0012;
		public const Int32 WM_RBUTTONDBLCLK = 0x0206;
		public const Int32 WM_RBUTTONDOWN = 0x0204;
		public const Int32 WM_RBUTTONUP = 0x0205;
		public const Int32 WM_RENDERALLFORMATS = 0x0306;
		public const Int32 WM_RENDERFORMAT = 0x0305;
		public const Int32 WM_SETCURSOR = 0x0020;
		public const Int32 WM_SETFOCUS = 0x0007;
		public const Int32 WM_SETFONT = 0x0030;
		public const Int32 WM_SETHOTKEY = 0x0032;
		public const Int32 WM_SETICON = 0x0080;
		public const Int32 WM_SETREDRAW = 0x000B;
		public const Int32 WM_SETTEXT = 0x000C;
		public const Int32 WM_SETTINGCHANGE = 0x001A;
		public const Int32 WM_SHOWWINDOW = 0x0018;
		public const Int32 WM_SIZE = 0x0005;
		public const Int32 WM_SIZECLIPBOARD = 0x030B;
		public const Int32 WM_SIZING = 0x0214;
		public const Int32 WM_SPOOLERSTATUS = 0x002A;
		public const Int32 WM_STYLECHANGED = 0x007D;
		public const Int32 WM_STYLECHANGING = 0x007C;
		public const Int32 WM_SYNCPAINT = 0x0088;
		public const Int32 WM_SYSCHAR = 0x0106;
		public const Int32 WM_SYSCOLORCHANGE = 0x0015;
		public const Int32 WM_SYSCOMMAND = 0x0112;
		public const Int32 WM_SYSDEADCHAR = 0x0107;
		public const Int32 WM_SYSKEYDOWN = 0x0104;
		public const Int32 WM_SYSKEYUP = 0x0105;
		public const Int32 WM_TCARD = 0x0052;
		public const Int32 WM_TIMECHANGE = 0x001E;
		public const Int32 WM_TIMER = 0x0113;
		public const Int32 WM_UNDO = 0x0304;
		public const Int32 WM_UNINITMENUPOPUP = 0x0125;
		public const Int32 WM_USER = 0x0400;
		public const Int32 WM_USERCHANGED = 0x0054;
		public const Int32 WM_VKEYTOITEM = 0x002E;
		public const Int32 WM_VSCROLL = 0x0115;
		public const Int32 WM_VSCROLLCLIPBOARD = 0x030A;
		public const Int32 WM_WINDOWPOSCHANGED = 0x0047;
		public const Int32 WM_WINDOWPOSCHANGING = 0x0046;
		public const Int32 WM_WININICHANGE = 0x001A;
		public const Int32 WM_XBUTTONDBLCLK = 0x020D;
		public const Int32 WM_XBUTTONDOWN = 0x020B;
		public const Int32 WM_XBUTTONUP = 0x020C;






		public const Int32 PRF_CHILDREN = 0x0010;
		public const Int32 PRF_CLIENT = 0x0004;

		[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
		public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);

		[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
		public static extern IntPtr GetDC(IntPtr hWnd);

		[DllImport("user32.dll", ExactSpelling = true)]
		public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		public static extern Bool DeleteDC(IntPtr hdc);

		[DllImport("gdi32.dll", ExactSpelling = true)]
		public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);

		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		public static extern Bool DeleteObject(IntPtr hObject);

		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
		public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
		public static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
		//[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
		//static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);
		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
		public static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, String lParam);
		[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
		public static extern void SendMessage(HandleRef hWnd, uint msg, IntPtr wParam, ref RECT lParam);
		//[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
		//static extern IntPtr SendMessage(HandleRef hWnd, uint msg, IntPtr wParam, ref POINT lParam);









	}
}
